import random
import matplotlib.pyplot as plt

a = [51, 33, 56, 45, 47, 50, 45, 46, 32, 42, 48, 50, 53, 34, 34, 34, 36, 53, 57, 55, 44, 55, 41, 49, 43, 53, 45, 37, 45,
     32, 37, 34, 36, 56, 30, 36, 41, 42, 47, 30, 50, 47, 39, 42,51, 33, 56, 45, 47, 50, 45, 46, 32, 42, 48, 50, 53, 34, 34, 34, 36, 53, 57, 55, 44, 55, 41, 49, 43, 53, 45, 37, 45,
     32, 37, 34, 36, 56, 30, 36, 41, 42, 47, 30, 50, 47, 39, 42,20,20,20,20]

d = 3  # 组距
num_bins = (max(a) - min(a)) // d     #计算组数

plt.grid(3)

plt.hist(a, num_bins)                  #频数分布—直方图  加,density=True就变成频率分布直方图

plt.xticks(range(min(a), max(a) + d,3))

plt.show()
